Skip to content

Add sponsor project: Numba and llvmlite in the browser#362

Open
MMesch wants to merge 3 commits into
QuantStack:masterfrom
MMesch:numba-llvmlite-wasm
Open

Add sponsor project: Numba and llvmlite in the browser#362
MMesch wants to merge 3 commits into
QuantStack:masterfrom
MMesch:numba-llvmlite-wasm

Conversation

@MMesch

@MMesch MMesch commented Jul 22, 2026

Copy link
Copy Markdown
Member
  • Add sponsor project for running Numba and llvmlite in the browser via WebAssembly

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@MMesch is attempting to deploy a commit to the QuantStack Team on Vercel.

A member of the Team first needs to authorize it.

@MMesch

MMesch commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

@anutosh491 @pitrou . This is a draft for a sponsorship project. I tried deliberately to keep it general without concrete funding amounts. But I think it's useful to already get it online and share our interest to work on this subject.

ps: for the sentence on the technical details of what is missing currently I just compiled roughly what you had in your text @Anutosh but I admit I don't really understand what those imply. So please correct anything you don't see fit.

Comment on lines +42 to +47
Numba work generally (e.g. with arrays). These likely include
WebAssembly's lack of writable-and-executable memory pages
(which rules out MCJIT), unsupported atomic instructions
without shared memory, variadic C calls that cannot be lowered
to WASM, and linkage incompatibilities in the LLVM WASM PIC
backend. But these seem surmountable based on our experience.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the details, some of which are probably wrong.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea could do. It would be nice to show that we have some idea about the non trivial parts though.

In the browser, multithreading/processing and GPU access are
mostly unavailable, and shipping pre-compiled native
extensions for everything is impractical. In addition, the
overhead of the Python interpreter is larger in the browser

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced the overhead of the Python interpreter is larger in the browser, unless you can link to an independent study.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's generally cited in the pyodide community. The standard numbers are <2.5x native for compiled stuff (based on a 2019 paper), 2-5x for python (cited on pyodide issues in their roadmap and more based on their benchmarks). If you actually look at the pyodide benchmarks you could say 2 -10x though. I'll put a reference in. I don't think they have rigorously isolated the effect of the interpreter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pyodide is not independent of course in that sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, perhaps link to a recent evaluation by PyOdide, then?
(I would stress recent, though; I wouldn't trust 2019 numbers to still apply currently, given that we're talking about a fast-moving ecosystem)

@MMesch MMesch Jul 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On performance numbers: I did a pretty long search and didn't find papers newer than the 2019 one. That paper "Not so Fast" is already an evolution to the older WASM paper which showed close to native performance for a different benchmark set. I recommend reading both. But the lack of newer studies is why new published benchmarks (even just as blog posts) for us, and for specific domains, are so important. The numbers I recently shared internally are all over the place, sometimes WASM is even a bit faster, often a bit (<2x) and sometimes much slower for compiled (10x+). But much is in the 2-5x range as the often cited numbers. My own numbers aren't able to isolate the interpreter overhead.

Pyodide has more numbers, but unfortunately they don't run their CI benchmarks regularly anymore it seems. You need to run them locally or find snapshots in issues. And even with those numbers available, to me the python browser overhead is anecdotal because I am unsure those benchmarks isolate the interpreter well (not because they are bad but because I didn't understand myself whether they do. And again, maybe I didn't find the right sources and others have a better understanding).

mostly unavailable, and shipping pre-compiled native
extensions for everything is impractical. In addition, the
overhead of the Python interpreter is larger in the browser
and many existing libraries use Numba, sometimes as hard

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and many existing libraries use Numba, sometimes as hard
and many existing scientific libraries use Numba, sometimes as hard

Comment on lines +24 to +25
mostly unavailable, and shipping pre-compiled native
extensions for everything is impractical. In addition, the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't "shipping pre-compiled native extensions" exactly what we do in emscripten-forge? Why would it be more impractical for the browser than for native code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key word is everything here. We can't ship compiled extensions for every loop and small code snippet. That is what is impractical on native and in the browser. Maybe it can be written better.

@pitrou pitrou Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this doesn't make sense either. The equation is for same for Wasm than it is for native code. Performance-critical Python scientific code is never written in pure Python. It's already available either in C/Rust/C++, or as Numba/Cython.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2-5x slower for pure Python code sounds severe, but it's also small compared to the 50-100x faster that you can get with C/C++/Rust vs. pure Python. So you would want native extensions in the same situations regardless of whether the Python interpreter is running in Wasm or not.

@MMesch MMesch Jul 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that depends on the situation and absolute numbers as well, 2x can be decisive or not at all.

Underlying is the argument that you have more incentives to JIT compile Python in the browser:

  • you generally pay a larger performance hit for Python in the browser than for compiled stuff (2x+ based on the numbers we cited).
  • it's more complicated to compile and load extensions manually in the browser. It's probably possible since done on the pyodide side afaik but seems involved in any case for the user.
  • you are in dynamic, notebook style situations requiring quick solutions that you can trigger immediately from the same interface.
  • What else would you do for acceleration? Multi threading, GPU aren't easily available.

And then you have libraries that use Numba anyway for acceleration and that might work out of the box if we had it available.

Comment on lines +56 to +57
to WebAssembly. Our team also includes Numba core developers,
giving us a direct upstream relationship.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not even sure I still have commit rights on Numba, and we have nobody else in the Numba team. So this sentence is a lie AFAICT.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, core developer is not correct? Or the upstream relationship?

@pitrou pitrou Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not contributed to Numba since 2017 or 2018, I think. I don't have any reliable evaluation of my upstream relationship, but I wouldn't count on it. By default you cannot assume that we are in a privileged position.

I do have expertise in Numba, though, and the internals don't seem to have changed much. So you could stress that we have in-house Numba expertise (and such expertise is rather rare).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that sounds good to me. We can just write it as such.


- upstream llvmlite compatibility with browser environments,
based on our existing patches.
- build a proof of concept for general Numba use in the browser to

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it's up to us to show a proof of concept before getting some funding. A sponsor will want dependable upstream changes for full-blown Numba functionality.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this as well. But my understanding is that the proof of concept itself is a significant undertaking, and probably the main challenge right now. Under that hypothesis, funding already for the PoC would be necessary because otherwise we may not be able to stem it ourselves.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the effort to demonstrate JIT-acceleration of NumPy array code is that significant. @anutosh491 could perhaps give more insight.

category: "Jupyter Ecosystem",
title: "Numba and llvmlite in the browser",
pageName: "NumbaInWasm",
shortDescription: "Numba, the standard JIT compiler for numerical Python, cannot run in Pyodide or emscripten-forge today. Its llvmlite backend relies on MCJIT, which WebAssembly does not allow. We have working demos of llvmlite and Numba scalar @jit in the browser. This proof-of-concept effort will resolve the remaining issues to make Numba work generally and initiate upstreaming of the patches.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the MCJIT tidbit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants